_Pragma("once");

#include <unordered_map>
#include <string>
#include<forward_list>
#include <vector>
#include <unistd.h>

#include "IExtendDeviceManager.h"

#include "SerialPortCommunicator485.h"


class ExtendDeviceManager : public IExtendDeviceManager {
public:
    friend class SingletonTemplate<ExtendDeviceManager>;
    /** Default destructor */
    ~ExtendDeviceManager();

    bool doWork() override {
        usleep(2400*1000);

        updateInnerDevice();

        mnewOnlineDevice.clear();

//   ExtendDevice* device;
        ChannelDevices* pChannelDevices = channelDevicesArray;
        bool allDeviceOnline = true;
        for (int i = 1; i < MDConst::DEFAULT_CHANNEL_COUNT; ++i) {//
            pChannelDevices = channelDevicesArray + i;

            allDeviceOnline = updateOnlineDevice(*pChannelDevices);

            if (!allDeviceOnline) {
                findExtendDevice(*pChannelDevices);
            }
        }

    //    if (!mnewOnlineDevice.empty()){
            Task* pTask = &mrefreshTask;
            mpool->pushPool(pTask);
     //   }

        return true;
    }


    bool updateOnlineDevice(ChannelDevices& channelDevices) override;

protected:

    ExtendDeviceManager();

    SerialPortCommunicator485 mouterCommunicator;
};


